'''
Author: duliang thinktanker@163.com
Date: 2025-05-11 15:23:44
LastEditors: duliang thinktanker@163.com
LastEditTime: 2025-05-11 15:53:56
FilePath:
Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
'''
import requests
import json


def get_jszj_data(url):
    headers = {
        'User-Agent':
        'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36 Edg/136.0.0.0',
        'Referer': 'http://www.jszj.com.cn/jgxx/011001/price.html?type=1',
        'Host': 'www.jszj.com',
        'Accept': 'application/json, text/javascript, */*; q=0.01',
        'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'zh-CN,zh;q=0.9',
        'Connection': 'keep-alive',
        'X-Requested-With': 'XMLHttpRequest'
    }
    resp = requests.get(url=url, headers=headers)
    return resp.json()


if __name__ == '__main__':
    url = 'http://www.jszj.com.cn/CostPriceAssociation/PriceWeb/PriceInformationSevert.ashx?methodname=GetMaterialModeBySiteId&sitename=宿迁'
    TemplateGuid_json = get_jszj_data(url)
    if TemplateGuid_json:
        TemplateGuid = TemplateGuid_json['data']['DataList'][0]['TemplateGuid']
        print(TemplateGuid)
    url = f'http://www.jszj.com.cn/CostPriceAssociation/PriceWeb/PriceInformationSevert.ashx?methodname=GetPeriodTagListByTemplateGuid&TemplateGuid={TemplateGuid}&YearCondition=>=2024'
    月报_json = get_jszj_data(url)
    if 月报_json:
        PeriodTag = 月报_json['data']['DataList'][0]['PeriodTag']
    url = f'http://www.jszj.com.cn/CostPriceAssociation/PriceWeb/PriceInformationSevert.ashx?methodname=getpagecitymaterialdetail&PeriodTag={PeriodTag}&TemplateGuid={TemplateGuid}&PageSize=16&CurrentPage=1&material=水泥'
    result_json = get_jszj_data(url)
    if result_json:
        data_list = result_json['data']['DataList']
        for data in data_list:
            print(data['MaterialCode'], data['MaterialName'],
                  data['Specification'], data['AnalysisPrice'],
                  data['ZhiDaoPrice_Current'], data['ZhiDaoPrice_Last'])
